package factory.one.command;

import com.alibaba.fastjson2.JSON;
import factory.one.entity.Batch;
import factory.one.service.BatchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Random;

/**
 * @author sk.z
 * 2023/7/5
 **/
@Service
public class CmdBatch {

    @Autowired
    private BatchService batchService;

    public void add(String orderId, String productId) {
        Batch batch = new Batch();
        batch.setOrderId(Long.valueOf(orderId));
        batch.setProductId(Long.valueOf(productId));
        batch.setOrderNum(new Random().nextInt(1000));
        batch.setRemark("remark");
        batch.setPrice(new Random().nextInt(100));
        batch.setAmount(batch.getPrice() * batch.getOrderNum());
        batchService.add(batch);
    }

    public void list() {
        batchService.list(null).forEach(e -> System.out.println(JSON.toJSONString(e)));
    }

}
